<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0px;
            padding: 0px;
        }
        div{
            width: 60px;
            height: 60px;
            background-color: brown;
            border-radius: 50%;
            position: absolute;
            transform: translate(-50%,-50%);
            display: none;
            text-align: center;
        }
        .box {
            display: block;
        }
        p{
            height: 30px;
        }
        body {
            height: 2000px;
        }
    </style>
</head>
<body>
    <div>
        <p><i>X:</i><span></span></p>
        <p><i>Y:</i><span></span></p>
    </div>
    <script>
        var divEle = document.querySelector("div");
        var pEles = document.querySelectorAll("span");
        // document.onmousemove = function ( event ) {
        //     var e = event || window.event ; 
        //     // console.log(e.pageX);
        //     divEle.className = 'box';
        //     pEles[0].innerHTML = e.pageX ; 
        //     pEles[1].innerHTML = e.pageY ;
        //     // console.log('相对浏览器左上角的横坐标:'+e.pageX,'相对浏览器左上角的纵坐标:'+e.pageY);
        //     divEle.style.left = `${e.pageX}px` ;
        //     divEle.style.top = `${e.pageY}px` ;
        // }
        
        document.onmousemove = function ( event ) {
            var e = event || window.event ;
            var a = document.documentElement.scrollTop ; 
            divEle.className = 'box';
            pEles[0].innerHTML = e.clientX ; 
            pEles[1].innerHTML = e.clientY ; 
            divEle.style.left = `${e.clientX}px` ;
            divEle.style.top = `${parseInt(e.clientY)+parseInt(a)}px` ;
        }
        document.onwheel = function ( event ) {
            // console.log(event);
            var e = event || window.event ;
            var a = document.documentElement.scrollTop ; 
            divEle.className = 'box';
            pEles[0].innerHTML = e.clientX ; 
            pEles[1].innerHTML = e.clientY ; 
            divEle.style.left = `${e.clientX}px` ;
            divEle.style.top = `${parseInt(e.clientY)+parseInt(a)}px` ;
        }
    </script>
</body>
</html>